//
//  MessageView.m
//  blipTest
//
//  Created by dawid on 08-12-17.
//  Copyright 2008 __MyCompanyName__. All rights reserved.
//

#import "MessageView.h"
#import "AppController.h"

#import "BlipMessage.h"

#import <Foundation/Foundation.h>

#import "ABlipConstants.h"

#define ABL_SUBJECT_REPLY @"reply"
#define ABL_SUBJECT_PICTURE @"picture"
#define ABL_SUBJECT_QUOTE @"quote"
#define ABL_SUBJECT_DELETE @"delete"
#define ABL_SUBJECT @"subject"

#define ABL_QUOTE_HTTP @"http://www.blip.pl/%@/%@"
#define ABL_DELETE_PATH @"%@/%@"


NSString* const ABL_ReplyClickedNotification=@"ABLReplyNotification";
NSString* const ABL_PictureClickedNotification=@"ABLPictureNotification";
NSString* const ABL_PictureMouseExitNotification=@"ABLPictureExitNotification";
NSString* const ABL_YoutubePictureClickedNotification=@"ABLYoutubePictureNotification";


@implementation MessageView




@synthesize textAttributes;
@synthesize opacity;

@synthesize replyIconRect;
@synthesize replyIconRollover;
@synthesize pictureIconRollover;
@synthesize pictureIconRect;

@synthesize quoteIconRect;

@synthesize quoteIconRollover;

@synthesize deleteIconRect;
@synthesize deleteIconRollover;
@synthesize defaultFrame;
@synthesize nextFrame;
@synthesize textView;



- (id)initWithFrame:(NSRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code here.
		opacity = 1;
		
		[[self window] setAcceptsMouseMovedEvents:YES];
		isYoutube2QtAvaible = NO;
		replyIconRect = NSMakeRect(4, USER_ACTION_ICON_Y, 13,13 );
		quoteIconRect = NSMakeRect(19, USER_ACTION_ICON_Y, 13,13);
		avatarRect = NSMakeRect(USER_AVATAR_X, USER_AVATAR_Y, 50, 50);
		
    }
    return self;
}
- (BOOL)acceptsFirstResponder
{
	return NO;
}
- (BOOL)isFlipped
{
	return YES;
}
+(NSSize)iconDefaultSize
{
	return NSMakeSize(13, 13);
}
+(NSSize)backgroundDefaultSize
{
	return NSMakeSize(330,95);
}
+(NSSize)avatarDefaultSize
{
	return NSMakeSize(50,50);
}
+(NSSize)avatarNoticeDefaultSize
{
	return NSMakeSize(50,30);
}
+(NSSize)avatarSmallDefaultSize
{
	return NSMakeSize(28,28);
}
+(NSRect)separatorRect
{
	return NSMakeRect(0, 0, 330, 1);
}
+(NSRect)pictureBackgroundRect
{
	return NSMakeRect(300, 20, 50, 50);
}
+(NSRect)pictureRect
{
	return NSMakeRect(300, 20, 45, 45);
}
+(NSRect)clipRect
{
	return NSMakeRect(310, 20, 15, 30);
}

//+(NSRect)

-(void)awakeFromNib
{
	
}
- (void)drawRect:(NSRect)rect {
    // Drawing code here.
	NSRect bounds = [self frame];
	

	if (blipMsg){
		
	/*		NSTimeInterval elapsedTime = [[blipMsg createdAt] timeIntervalSinceNow];
#ifdef __DEBUG__

			NSLog(@"time elapsed:%f",elapsedTime);

#endif
			if (elapsedTime>3600*24){
				date = [NSString stringWithString:@"wczoraj,"];	
			}
	 
	*/	
			
			
						
			[self drawDescriptionStringInRect:descriptionText inRect:userDescRect];

		
#ifdef __DEBUG__

		//NSLog(@"drawing mg %@", [blipMsg msgId]);

#endif
			
		
	}
	
}
-(void)setIconsAndDescriptionRects
{
  NSRect avatarFrame = [avatarView frame];
  NSRect frame  = [self frame];
  float textBottom = USER_MSG_TEXT_Y + [textView frame].size.height;
  float avatarBottom = avatarFrame.origin.y + avatarFrame.size.height;
  if (!pictureView) {
    if (avatarBottom < textBottom) {
      [self setFrame:NSMakeRect(frame.origin.x, frame.origin.y, frame.size.width, textBottom+2+replyIconRect.size.height)];
    } else {
      [self setFrame:NSMakeRect(frame.origin.x, frame.origin.y, frame.size.width, avatarFrame.size.height+avatarFrame.origin.y+2+replyIconRect.size.height)];
    }
  } else {
    if (pictureView.frame.origin.y+pictureView.frame.size.height > textBottom) {
      [self setFrame:NSMakeRect(frame.origin.x, frame.origin.y, frame.size.width, pictureView.frame.origin.y+pictureView.frame.size.height+2+replyIconRect.size.height)];
    } else {
      [self setFrame:NSMakeRect(frame.origin.x, frame.origin.y, frame.size.width, textBottom + BLIP_VIEW_ADDITION_TO_HEIGHT)];
    }
  }
  float iconsOriginY = [self frame].size.height- 13;
  
  replyIconRect = NSMakeRect(BLIP_REPLY_ICON_X, iconsOriginY , replyIconRect.size.width, replyIconRect.size.height);
  [replyView setFrame:replyIconRect];
  quoteIconRect = NSMakeRect( BLIP_QUOTE_ICON_X, iconsOriginY , quoteIconRect.size.width, quoteIconRect.size.height);
  [quoteView setFrame:quoteIconRect];
  userDescRect = NSMakeRect( BLIP_DESCR_X, iconsOriginY , userDescRect.size.width, userDescRect.size.height);
  [self setNeedsDisplay:YES];		
  
  return;
//	//jesli wysoko text-u < 45 i nie ma zdjecia przenosimy kolo ikonki
//	float textBottom = USER_MSG_TEXT_Y + [textView frame].size.height;
//		NSRect avatarFrame = [avatarView frame];
//	float avatarBottom = avatarFrame.origin.x + avatarFrame.size.height;
//	if (YES || textBottom < avatarBottom -13  && !pictureView){
//
//#ifdef __DEBUG__
//
//		//NSLog(@"rysuje dla %@", [[self blipMsg] body]);
//
//#endif
//		NSRect avatarFrame = [avatarView frame];
//		NSRect frame  = [self frame];
//		[self setFrame:NSMakeRect(frame.origin.x, frame.origin.y, frame.size.width, avatarFrame.size.height+avatarFrame.origin.y+2)];
//		float iconsOriginY = avatarFrame.size.height + avatarFrame.origin.y - 13;
//		float iconsOriginX = avatarFrame.origin.x  + avatarFrame.size.width;
//		replyIconRect = NSMakeRect(iconsOriginX + BLIP_REPLY_ICON_X, iconsOriginY , replyIconRect.size.width, replyIconRect.size.height);
//		[replyView setFrame:replyIconRect];
//		quoteIconRect = NSMakeRect(iconsOriginX + BLIP_QUOTE_ICON_X, iconsOriginY , quoteIconRect.size.width, quoteIconRect.size.height);
//		[quoteView setFrame:quoteIconRect];
//		userDescRect = NSMakeRect(iconsOriginX + BLIP_DESCR_X, iconsOriginY , userDescRect.size.width, userDescRect.size.height);
//		[self setNeedsDisplay:YES];
//	}else if (avatarBottom <= textBottom){
//		
//		NSRect frame  = [self frame];
//		[self setFrame:NSMakeRect(frame.origin.x, frame.origin.y, frame.size.width, textBottom + BLIP_VIEW_ADDITION_TO_HEIGHT)];
//#ifdef __DEBUG__
//
//		//NSLog(@"rysuje2  dla %@", [[self blipMsg] body]);
//
//#endif 
//		float y = textBottom;// + replyIconRect.size.height;
//		replyIconRect = NSMakeRect(BLIP_REPLY_ICON_X, y, replyIconRect.size.width, replyIconRect.size.height);
//		[replyView setFrame:replyIconRect];
//		quoteIconRect = NSMakeRect(BLIP_QUOTE_ICON_X, y , quoteIconRect.size.width, quoteIconRect.size.height);
//		[quoteView setFrame:quoteIconRect];
//		userDescRect = NSMakeRect(BLIP_DESCR_X, y , userDescRect.size.width, userDescRect.size.height);
//		[self setNeedsDisplay:YES];
//		
//	}else if (!pictureView){
//		NSRect avatarFrame = [avatarView frame];
//		NSRect frame  = [self frame];
//		[self setFrame:NSMakeRect(frame.origin.x, frame.origin.y, frame.size.width, avatarFrame.size.height+avatarFrame.origin.y+2+replyIconRect.size.height)];
//		float iconsOriginY = [self frame].size.height- 13;
//		
//		replyIconRect = NSMakeRect(BLIP_REPLY_ICON_X, iconsOriginY , replyIconRect.size.width, replyIconRect.size.height);
//		[replyView setFrame:replyIconRect];
//		quoteIconRect = NSMakeRect( BLIP_QUOTE_ICON_X, iconsOriginY , quoteIconRect.size.width, quoteIconRect.size.height);
//		[quoteView setFrame:quoteIconRect];
//		userDescRect = NSMakeRect( BLIP_DESCR_X, iconsOriginY , userDescRect.size.width, userDescRect.size.height);
//		[self setNeedsDisplay:YES];		
//	}

}
+ (NSImage *)rotateIndividualImage: (NSImage *)image clockwise: (BOOL)clockwise rotateBy:(int)degrees
{
	//skwadratowacenie :)
	
	NSImage *existingImage;
	NSSize size = [image size];
	
	if (size.height >= size.width){
		float minSize = size.width;
		float offset = (size.height - size.width)/2;
		existingImage = [[NSImage alloc] initWithSize:NSMakeSize(minSize, minSize)];
		[existingImage lockFocus];
		[image drawInRect:NSMakeRect(0, 0, minSize, minSize) fromRect:NSMakeRect(0, offset, minSize, minSize) operation:NSCompositeSourceOver fraction:1];
		[existingImage unlockFocus];
	} else{
		float minSize = size.height;
		float offset = (size.width - size.height)/2;
		existingImage = [[NSImage alloc] initWithSize:NSMakeSize(minSize, minSize)];
		[existingImage lockFocus];
		[image drawInRect:NSMakeRect(0, 0, minSize, minSize) fromRect:NSMakeRect(offset, 0, minSize, minSize) operation:NSCompositeSourceOver fraction:1];
		[existingImage unlockFocus];
	}

	
	
	
    //NSImage *existingImage = image;
    NSSize existingSize;
	
    /**
     * Get the size of the original image in its raw bitmap format.
     * The bestRepresentationForDevice: nil tells the NSImage to just
     * give us the raw image instead of it's wacky DPI-translated version.
     */
    existingSize.width = [[existingImage bestRepresentationForDevice: nil] pixelsWide];
    existingSize.height = [[existingImage bestRepresentationForDevice: nil] pixelsHigh];
	
    NSSize newSize = NSMakeSize(existingSize.height, existingSize.width);
    NSImage *rotatedImage = [[NSImage alloc] initWithSize:newSize];
	
    [rotatedImage lockFocus];
	
    /**
     * Apply the following transformations:
     *
     * - bring the rotation point to the centre of the image instead of
     *   the default lower, left corner (0,0).
     * - rotate it by 90 degrees, either clock or counter clockwise.
     * - re-translate the rotated image back down to the lower left corner
     *   so that it appears in the right place.
     */
    NSAffineTransform *rotateTF = [NSAffineTransform transform];
    NSPoint centerPoint = NSMakePoint(newSize.width / 2, newSize.height / 2);
	
    [rotateTF translateXBy: centerPoint.x yBy: centerPoint.y];
    [rotateTF rotateByDegrees: (clockwise) ? - degrees : degrees];
    [rotateTF translateXBy: -centerPoint.y yBy: -centerPoint.x];
    [rotateTF concat];
	
    /**
     * We have to get the image representation to do its drawing directly,
     * because otherwise the stupid NSImage DPI thingie bites us in the butt
     * again.
     */
    NSRect r1 = NSMakeRect(0, 0, newSize.height, newSize.width);
    [[existingImage bestRepresentationForDevice: nil] drawInRect: r1];
	
    [rotatedImage unlockFocus];
	
    return rotatedImage;
}
-(void)dealloc{
	

	if (pictureView){
		[pictureView removeFromSuperview];
		[pictureView release];
		pictureView = nil;
	}
	if(quoteView){
		[quoteView removeFromSuperview];
		[quoteView release];
		quoteView = nil;
	}
	if(replyView){
		[replyView removeFromSuperview];
		[replyView release];
		replyView = nil;
	}
	if(backgroundView){
		[backgroundView removeFromSuperview];
		[backgroundView release];
		backgroundView = nil;
	}
	if (textAttributes){
		[textAttributes release];
		textAttributes = nil;
	}
	if (textView){
		[textView removeFromSuperview];
		[textView release];
		textView =nil;
	}
	if (blipMsg){
		[blipMsg release];
		blipMsg =nil;
	}
	if(descriptionText){
		[descriptionText release];
		descriptionText = nil;
	}
	for (int i=0; i < [[self trackingAreas] count]; i++){
		[self removeTrackingArea:[[self trackingAreas] objectAtIndex:i]];
	}
	[super dealloc];
}

-(void)drawDescriptionStringInRect:(NSString*)string1 inRect:(NSRect)r
{
	
	
	[string1 drawInRect:r withAttributes:[MessageView blipDescriptionTextAttributes]];
	
}
-(NSImage*)maskedAvatar:(NSString*)avatarPath
{

	NSImage *pierwszyImage;
	while(pierwszyImage==nil){
		pierwszyImage= [[NSImage alloc] initWithData:[NSData dataWithContentsOfFile: avatarPath]];					
	}
	NSImage *drugiImage = [NSImage imageNamed:@"avatar-mask"];

	NSImage* result = [[NSImage alloc] initWithSize:[drugiImage size]];

	[result lockFocus];

	[pierwszyImage drawAtPoint:NSZeroPoint fromRect:NSMakeRect(0,0, 50,50) operation:NSCompositeCopy fraction:1];
	[drugiImage drawAtPoint:NSZeroPoint fromRect:NSMakeRect(0,0, 50,50) operation:9 fraction:1];
	
	[result unlockFocus];

	[result setSize:[MessageView avatarDefaultSize]];
	[pierwszyImage release];
	pierwszyImage = nil;
	drugiImage = nil;
	return result;
}
-(void)setBlipMsg:(BlipMessage*)msg
{
			
	[msg retain];
	[blipMsg release];
	blipMsg = msg;
	[msg retain];
	if (msg != nil){
		if ([blipMsg msgType] ==nil){
			[blipMsg setMsgType:@""];
		}
		NSRect frame;
		//ustawienie tla

		[self setBackgroundView];

		//if ([ blipMsg picturePath] !=nil && [blipMsg pictureData] != nil){
#ifdef __DEBUG__

//			//NSLog(@"zdjecia path = %@", [blipMsg picturePath]);

#endif
//			[self setPictureView:[blipMsg pictureData]];
//			
//			frame = NSMakeRect(USER_MSG_TEXT_X, USER_MSG_TEXT_Y, USER_MSG_TEXT_WIDTH_WITH_PICT , 10);
//		} else {
//			frame = NSMakeRect(USER_MSG_TEXT_X,USER_MSG_TEXT_Y, USER_MSG_TEXT_WIDTH_NO_PICT, 10);
//		}
		[self setPictureView:[blipMsg pictureData]];
		if (pictureView){
			
			frame = NSMakeRect(USER_MSG_TEXT_X, USER_MSG_TEXT_Y, USER_MSG_TEXT_WIDTH_WITH_PICT , 10);
		} else {
			frame = NSMakeRect(USER_MSG_TEXT_X,USER_MSG_TEXT_Y, USER_MSG_TEXT_WIDTH_NO_PICT, 10);
		}
		//description

		if ([blipMsg userName]){
			NSString *date;
			date = [ [blipMsg createdAt] descriptionWithCalendarFormat:@"%H:%M:%S"];
			NSString* user;
			if ([blipMsg recipientName]!=nil && [[blipMsg recipientName] isEqualToString:[[AppController shared] userLogin]] == NO){
				user = [NSString stringWithString:[blipMsg recipientName]];
				if (!date){
					descriptionText = [NSString stringWithFormat:@"do %@", user ];	
				}else {
					descriptionText = [NSString stringWithFormat:@"do %@ o %@", user,date ];
				}
			} else{
				user = [NSString stringWithString:[blipMsg userName]];
				if (!date){
					descriptionText = [NSString stringWithFormat:@"%@", user ];	
				}else {
					descriptionText = [NSString stringWithFormat:@"%@ o %@", user,date ];
				}
			}
			NSSize size = [descriptionText sizeWithAttributes:[MessageView blipDescriptionTextAttributes]];
			NSRect r = NSMakeRect(r.origin.x, r.origin.y, size.width, size.height);
			userDescRect = NSMakeRect(BLIP_DESCR_X, [self bounds].size.height - BLIP_VIEW_ICONS_Y_OFFSET , size.width, 13);
		}
#ifdef __DEBUG__

		//NSLog(@"text dla %@= %@",[blipMsg msgId], text);

#endif
		
		
		
		
		textView = [[TextViewLinked alloc] initWithFrame:frame];
		
		[textView setTypingAttributes:[MessageView blipTextAttributes]];
		[textView setDrawsBackground:NO];
		[textView setEditable:NO];
		//[textView setSelectable:YES];
		[textView setRichText:NO];

		//dodanie do poczatku wiadomosci klodki, jesli jest prywatnamon
		if ([[msg msgType] isEqualTo:@"PrivateMessage"] == YES){
			NSImage *attImage = [[NSImage imageNamed:@"lockLocked.png"] autorelease];
			NSTextAttachment* attachment = [[[NSTextAttachment alloc] init] autorelease];
			
			NSCell *cell = [attachment attachmentCell];
			[cell setImage:attImage];
			
			NSAttributedString* attachmentString = [NSAttributedString attributedStringWithAttachment:attachment];
			//NSAttributedString* attributedBody = [[NSAttributedString alloc] initWithString:  [NSString stringWithFormat:@" %@",  [msg body]] attributes:[MessageView blipTextAttributes]];

			NSTextStorage* textStorage = [textView textStorage];
			[textStorage beginEditing];
			[textStorage appendAttributedString:attachmentString];
			[textStorage appendAttributedString:[[NSAttributedString alloc] initWithString: @" " attributes:[MessageView blipTextAttributes]]];
			[textStorage appendAttributedString:[[self blipMsg] attributedBody] ];
			[textStorage endEditing];

		}else {
			//NSAttributedString* attributedBody = [[NSAttributedString alloc] initWithString: [msg body] attributes:[MessageView blipTextAttributes]];
			NSTextStorage* textStorage = [textView textStorage];
			[textStorage beginEditing];
			[textStorage appendAttributedString:[[self blipMsg]attributedBody]];
			[textStorage endEditing];
			
		}
		//	[textView setAutoresizingMask:    48];
		[textView createLink];
		frame = [textView frame];
#ifdef __DEBUG__

    NSLog(@"self frame = %f", frame.size.height);

#endif

		
		//ustawienie avatara
		
		
		//ustawienie ikonek
#ifdef __DEBUG__

		//NSLog(@"self frame = %f", [self frame].size.height);

#endif
		[self addSubview:textView];
		//if ([textView frame].size.height > 65){
//			NSRect frame  = [self frame];
//			[self setFrame:NSMakeRect(frame.origin.x, frame.origin.y, frame.size.width, [self frame].size.height + BLIP_VIEW_ADDITION_TO_HEIGHT)];
//		}
		[self setIconsView];
		[self setAvatarView];
		[self setIconsAndDescriptionRects];
		//textView = nil;
	}
	[self setNeedsDisplay:YES];
}
-(BlipMessage*)blipMsg
{
	return blipMsg;
}
-(void)setOpacity:(float)value
{
	if (value>1.0){
		opacity = 1.0;
	}else{
		opacity = value;
	}
	[self setAlphaValue:value];
	[self setNeedsDisplay:YES];
}
#pragma mark font_sizing
-(BOOL)incFontSize
{
	NSFont *font= [[textView textStorage] font];

	NSMutableDictionary* attributes = [[font fontDescriptor] fontAttributes];	
	NSNumber *size= [attributes objectForKey:NSFontSizeAttribute];
	
	
	if ([size floatValue] >20)
		return FALSE;
	font = [NSFont fontWithName:[attributes objectForKey:NSFontNameAttribute] size:[size floatValue]+1];
	float prevTextH = [textView frame].size.height;
	NSTextStorage *textStorage =  [textView textStorage];
	[textStorage beginEditing];
	[textStorage setFont:font];
	[textStorage endEditing];
	[textView setNeedsDisplay:YES];
	[[MessageView blipTextAttributes] setObject:font forKey:NSFontAttributeName];
#ifdef __DEBUG__

	NSLog(@" after wys = %f", [textView frame].size.height);

#endif
	float additionH = [textView frame].size.height - prevTextH;
	if ([textView frame].size.height > 65){
		NSRect frame  = [self frame];
		[self setFrame:NSMakeRect(frame.origin.x, frame.origin.y, frame.size.width,  frame.size.height + additionH )];
	}
	[self setIconsAndDescriptionRects];
	return TRUE;

}
-(BOOL)decFontSize
{
	NSFont *font= [[textView textStorage] font];
	NSMutableDictionary* attributes = [[font fontDescriptor] fontAttributes];
	NSNumber *size= [attributes objectForKey:NSFontSizeAttribute];
	if ([size floatValue] <7)
		return FALSE;
	font = [NSFont fontWithName:[attributes objectForKey:NSFontNameAttribute] size:[size floatValue]-1];
	float prevTextH = [textView frame].size.height;
	NSTextStorage *textStorage =  [textView textStorage];
	[textStorage beginEditing];
	[textStorage setFont:font];
	[textStorage endEditing];
	[[MessageView blipTextAttributes] setObject:font forKey:NSFontAttributeName];
	float additionH = [textView frame].size.height - prevTextH;
	if ([textView frame].size.height > 65){
		NSRect frame  = [self frame];
		[self setFrame:NSMakeRect(frame.origin.x, frame.origin.y, frame.size.width,  frame.size.height + additionH)];
	}
		[self setIconsAndDescriptionRects];
	return TRUE;
	
}

#pragma mark setting_views
-(void)setBackgroundView
{
	if(backgroundView)
		return;
	NSBundle *bundle = [NSBundle mainBundle];
	backgroundView = [[ClickableNSImageView alloc] initWithFrame:NSMakeRect(9,USER_BACKGROUND_Y,0, 0)];
	if ([blipMsg msgType] == nil){
			
			[backgroundView setImage:[[NSImage alloc] initWithContentsOfFile: [bundle pathForResource:@"blipRegular-background" ofType:@"png"]]];//[NSImage imageNamed:@"blipRegular-background.png"]];
	} else {	
		if ([[blipMsg msgType] isEqualToString:@"PrivateMessage"]==YES ){
			[backgroundView setImage: [[NSImage alloc] initWithContentsOfFile: [bundle pathForResource:@"blipPrivate-background" ofType:@"png"]]];//[NSImage imageNamed:@"blipPrivate-background.png"]];
			
		} else if ([[blipMsg msgType] isEqualToString:@"DirectedMessage"]==YES){
			[backgroundView setImage:[[NSImage alloc] initWithContentsOfFile: [bundle pathForResource:@"blipDirect-background" ofType:@"png"]]];//[NSImage imageNamed:@"blipDirect-background.png"]];
			
		}else if ([[blipMsg msgType] isEqualToString:@"Notice"]==YES){
			[backgroundView setImage:[[NSImage alloc] initWithContentsOfFile: [bundle pathForResource:@"blipAlert-background" ofType:@"png"]]];//[NSImage imageNamed:@"blipAlert-background.png"]];
			
		}else {
			
			[backgroundView setImage:[[NSImage alloc] initWithContentsOfFile: [bundle pathForResource:@"blipRegular-background" ofType:@"png"]]];//[NSImage imageNamed:@"blipRegular-background.png"]];
		}
	}
	[backgroundView setFrameSize:NSMakeSize([[backgroundView image]size].width, [[backgroundView image]size].height)];
	[self setFrameSize:NSMakeSize(BLIP_VIEW_WIDTH, BLIP_VIEW_HEIGHT)];
	[self addSubview:backgroundView]; 

}
-(void)setAvatarView
{
	NSImage *avatarTo = nil;
	NSImage *avatarFrom = nil;
	
	if (avatarView)
		return;
	[avatarTo setScalesWhenResized:YES];
	[avatarFrom setScalesWhenResized:YES];
	[avatarTo setCacheMode:NSImageCacheNever];
	[avatarFrom setCacheMode:NSImageCacheNever];
	NSBundle *bundle =  [NSBundle mainBundle];
	if ([blipMsg msgType] == nil){
#ifdef __DEBUG__

		NSLog(@"msgtype is nol");

#endif
	}
	if ( [[blipMsg msgType] isEqualToString:@"Notice"] || [[blipMsg msgType] isEqualToString:@"UpdateTip"]){
		
		avatarTo = [[NSImage alloc] initWithContentsOfFile: [bundle pathForResource:@"blip" ofType:@"png"]];
		[avatarTo setSize:[MessageView avatarNoticeDefaultSize]];
		
	}
	else if ([blipMsg userAvatarPath] !=nil && [[blipMsg userAvatarPath] isEqualToString:@""]==NO){
		
		
		if ([blipMsg recipientAvatarPath] != nil && [[blipMsg recipientAvatarPath] isEqualToString:@""] == NO){
			NSRect avatarRet;
			
			avatarRet.origin = NSZeroPoint;
			
			NSImage *pierwszyImage;
			NSImage *drugiImage;
			
			//if ([self avatarTo] ==nil){
			
			pierwszyImage = [[NSImage alloc] initWithContentsOfFile:[blipMsg userAvatarPath]];
			if (pierwszyImage == nil){
				usleep(1000);
				pierwszyImage = [[NSImage alloc] initWithContentsOfFile:[blipMsg userAvatarPath]];
				if (pierwszyImage == nil)
					pierwszyImage = [[NSImage alloc] initWithContentsOfFile: [bundle pathForResource:@"avatarDefault" ofType:@"png"]];
			}
			drugiImage =  [[NSImage alloc] initWithContentsOfFile: [bundle pathForResource:@"avatar-mask" ofType:@"png"]];
			[pierwszyImage setSize:[drugiImage size]];
			avatarRet.size = [drugiImage size];
			avatarTo = [[NSImage alloc] initWithSize:[drugiImage size]];
			
			[avatarTo lockFocus];
			
			[pierwszyImage drawAtPoint:NSZeroPoint fromRect:NSMakeRect(0,0, 50,50) operation:NSCompositeCopy fraction:1];
			[drugiImage drawAtPoint:NSZeroPoint fromRect:NSMakeRect(0,0, 50,50) operation:9 fraction:1];
			
			[avatarTo unlockFocus];
			
			
			[pierwszyImage release];
			pierwszyImage = nil;
			[drugiImage release];
			drugiImage = nil;
			
			[avatarTo setScalesWhenResized:YES];
			[avatarTo setSize:[MessageView avatarDefaultSize]];				
			
			pierwszyImage = [[NSImage alloc] initWithContentsOfFile:[blipMsg recipientAvatarPath]];
			if (pierwszyImage == nil){
				usleep(1000);
				pierwszyImage = [[NSImage alloc] initWithContentsOfFile:[blipMsg recipientAvatarPath]];
				if(pierwszyImage == nil)
					pierwszyImage = [[NSImage alloc] initWithContentsOfFile: [bundle pathForResource:@"avatarDefault" ofType:@"png"]];
			}
			drugiImage =  [[NSImage alloc] initWithContentsOfFile: [bundle pathForResource:@"avatar-mask" ofType:@"png"]];
			[pierwszyImage setSize:[drugiImage size]];
			avatarFrom = [[NSImage alloc] initWithSize:[drugiImage size]];
			
			[avatarFrom lockFocus];
			
			[pierwszyImage drawAtPoint:NSZeroPoint fromRect:NSMakeRect(0,0, [drugiImage size].width,[drugiImage size].height) operation:NSCompositeCopy fraction:1];
			[drugiImage drawAtPoint:NSZeroPoint fromRect:NSMakeRect(0,0,  [drugiImage size].width,[drugiImage size].height) operation:9 fraction:1];
			
			[avatarFrom unlockFocus];
			
			if (pierwszyImage){
				[pierwszyImage release];
				pierwszyImage = nil;
			}
			if (drugiImage){
				[drugiImage release];
				drugiImage = nil;
			}
			[avatarFrom setScalesWhenResized:YES];
			[avatarFrom setSize:[MessageView avatarDefaultSize]];	
			

			NSImage *podwojny = [[NSImage alloc] initWithSize:[MessageView avatarDefaultSize]];
			NSRect rect1= NSMakeRect(0, 20, 28,30);
			NSRect rect2 = NSMakeRect(20, 0, 28,30);
			[podwojny lockFocus];
			[avatarTo drawInRect:rect1 fromRect:avatarRet operation:NSCompositeSourceOver fraction:1];
			[avatarFrom drawInRect:rect2 fromRect:avatarRet operation:NSCompositeSourceOver fraction:1];
			[podwojny unlockFocus];
			
			if (avatarTo){
				[avatarTo release];
				avatarTo = nil;
			}
			if (avatarFrom){
				[avatarFrom release];
				avatarFrom = nil;
			}
			
			avatarTo = podwojny;
			
		} else {
			
			
			NSImage *pierwszyImage;
			NSImage *drugiImage;
			NSRect avatarRet;

			avatarRet.origin = NSZeroPoint;
			avatarRet.size = NSMakeSize(50, 50);
			
			pierwszyImage= [[NSImage alloc]initWithContentsOfFile: [blipMsg userAvatarPath]];	
			if (pierwszyImage == nil){
				usleep(1000);
				pierwszyImage = [[NSImage alloc] initWithContentsOfFile:[blipMsg userAvatarPath]];
				
				if (pierwszyImage == nil)
					pierwszyImage = [[NSImage alloc] initWithContentsOfFile: [bundle pathForResource:@"avatarDefault" ofType:@"png"]];
			}
			[pierwszyImage setScalesWhenResized:YES];
			[pierwszyImage setSize:[MessageView avatarDefaultSize]];
			
			
			drugiImage = [[NSImage alloc] initWithContentsOfFile: [bundle pathForResource:@"avatar-mask" ofType:@"png"]];
			
			avatarTo = [[NSImage alloc] initWithSize:[drugiImage size]];
//				avatarTo = [[NSImage alloc] initWithSize:NSMakeSize(40, 40)];
			
			[avatarTo lockFocus];
			//[[MessageView avatarShadow ]set];
			
			[pierwszyImage drawAtPoint:NSZeroPoint fromRect:NSMakeRect(0,0, 50,50) operation:NSCompositeCopy fraction:1];
			
			[drugiImage drawAtPoint:NSZeroPoint fromRect:NSMakeRect(0,0, 50,50) operation:9 fraction:1];
			
			
			[avatarTo unlockFocus];
			
			
			
			[avatarTo setSize:[MessageView avatarDefaultSize]];
			
			/*NSShadow *shadow = [[NSShadow alloc] init];
			[shadow setShadowColor: [NSColor blackColor]];// [NSColor colorWithCalibratedRed:shadowColor green:shadowColor blue:shadowColor alpha:1]];
			[shadow setShadowBlurRadius:5];
			[shadow setShadowOffset: NSMakeSize(2, -2)];
			[shadow set];
			
			NSRect imageRect = NSMakeRect(0, 0, [avatarTo size].width, [avatarTo size].height);
			NSRect photoRect = NSMakeRect(0, 0, [avatarTo size].width+2, [avatarTo size].height+2);
			[avatarTo drawInRect:photoRect fromRect:imageRect operation:NSCompositeCopy fraction:1.0];
			*/
			if (pierwszyImage){
				[pierwszyImage release];
				pierwszyImage = nil;
			}
			if (drugiImage){
				[drugiImage release];
				drugiImage = nil;
			}		


		}
	} else {

		avatarTo = [[NSImage alloc] initWithContentsOfFile: [bundle pathForResource:"blip" ofType:"png"]];
		[avatarTo setSize:[MessageView avatarDefaultSize]];
	}
	/*NSShadow *shadow = [[NSShadow alloc] init];
	[shadow setShadowColor: [NSColor blackColor]];
	[shadow setShadowBlurRadius:5];
	[shadow setShadowOffset: NSMakeSize(10,0)];
	[shadow set];
	
	NSRect imageRect = NSMakeRect(0, 0, [avatarTo size].width+10, [avatarTo size].height+10);
	NSRect photoRect = NSMakeRect(0, 0, [avatarTo size].width+10, [avatarTo size].height+10);
	NSImage *imageShaded = [[NSImage alloc] initWithSize:NSMakeSize(60, 60)];
	[imageShaded lockFocus];
	//[[MessageView avatarShadow ]set];
	
	[avatarTo drawAtPoint:NSZeroPoint fromRect:NSMakeRect(0,0, 50,50) operation:NSCompositeCopy fraction:1];
//	[avatarTo drawInRect:photoRect fromRect:imageRect operation:NSCompositeCopy fraction:1.0];
	
	[imageShaded unlockFocus];
	avatarTo = imageShaded;
	*/
	avatarView  = [[ClickableNSImageView alloc] initWithFrame:NSMakeRect(USER_AVATAR_X, USER_AVATAR_Y, [avatarTo size].width, [avatarTo size].height)];
	[avatarView setImage:avatarTo];
	[self addSubview:avatarView];
	[avatarTo release];
	if (avatarTo){
		[avatarTo release];
		avatarTo = nil;
	}
}
-(void)setPictureView:(NSData*)pictureData
{
	NSImage* picture;
	if (pictureView || pictureData == nil ){
		if (![blipMsg youtubeQtLink])
			return;
	}

	NSBundle *bundle = [NSBundle mainBundle];
	NSImage *pierwszyImage =[[NSImage alloc] initWithData: pictureData];
	if ([pierwszyImage size].width ==0 || [pierwszyImage size].height ==0){
		[pierwszyImage release];
		pierwszyImage = nil;
		if (![blipMsg youtubeQtLink] || ![blipMsg youtubeThumbnail])
			return;
		pierwszyImage =[[NSImage alloc] initWithData: [blipMsg youtubeThumbnail]];
		pierwszyImage = [MessageView rotateIndividualImage:pierwszyImage
											clockwise:YES 
											  rotateBy:10];
		isYoutube2QtAvaible = YES;
	}
	[pierwszyImage setScalesWhenResized:YES];
	NSImage *drugiImage = [[NSImage alloc] initWithContentsOfFile: [bundle pathForResource:@"attachment-mask" ofType:@"png"]];  //[NSImage imageNamed:@"attachment-mask.png"];
	[pierwszyImage setSize:[drugiImage size]];
	picture =  [[NSImage alloc] initWithSize:[drugiImage size]];
	NSImage *trzeciImage =  [[NSImage alloc] initWithContentsOfFile: [bundle pathForResource:@"attachment-overlay" ofType:@"png"]];// [NSImage imageNamed:@"attachment-overlay.png"];
	[trzeciImage setSize:[drugiImage size]];
	[picture lockFocus];
	
	[pierwszyImage drawAtPoint:NSZeroPoint fromRect:NSMakeRect(0,0, [pierwszyImage size].width, [pierwszyImage size].height) operation:NSCompositeCopy fraction:1];
	[drugiImage drawAtPoint:NSZeroPoint fromRect:NSMakeRect(0,0, [drugiImage size].width, [drugiImage size].height) operation:9 fraction:1];
	[trzeciImage drawAtPoint:NSZeroPoint fromRect:NSMakeRect(0,0, [drugiImage size].width, [drugiImage size].height) operation:NSCompositeSourceOver fraction:1];
	
	[ picture unlockFocus];
	if (pierwszyImage){
		[pierwszyImage release];
		pierwszyImage = nil;
	}
	if (drugiImage){
		[drugiImage release];
		drugiImage = nil;
	}
	if (trzeciImage){
		[trzeciImage release];
		trzeciImage = nil;
	}
	NSRect replyRect;
	replyRect.origin = NSZeroPoint;
	replyRect.size =  [picture size];
	pictureIconRect = NSMakeRect([self bounds].size.width - 80, USER_PICTURE_Y, [picture size].width, [picture size].height);
	pictureView  = [[ClickableNSImageView alloc] initWithFrame:pictureIconRect];
	[pictureView setImage:picture];
	[self setFrameSize:NSMakeSize(BLIP_VIEW_WIDTH, BLIP_VIEW_HEIGHT_WITH_PICT)];
	[self addSubview:pictureView];
	if (picture){
		[picture release];
		picture= nil;
	}
	//zpisanie 
	NSFileManager *fm = [NSFileManager defaultManager];
	NSString *path  = [[AppController picturesDownloadDir] stringByAppendingPathComponent:[[blipMsg picturePath] lastPathComponent]];
	NSError *error;
	if ([fm createDirectoryAtPath:[path stringByDeletingLastPathComponent] withIntermediateDirectories:YES attributes:nil error:&error]==NO){
#ifdef __DEBUG__

		NSLog(@"Error while creating directory:%@", [error description]);

#endif	
		return;
		
	} 
	[fm createFileAtPath:path contents:[blipMsg pictureData] attributes:nil];
	
}
-(void)setIconsView
{
	NSRect frame = [self frame];
	NSRect replyRect = NSMakeRect(BLIP_REPLY_ICON_X, frame.size.height - BLIP_VIEW_ICONS_Y_OFFSET, 13, 13);
	NSRect quoteRect = NSMakeRect(BLIP_QUOTE_ICON_X, frame.size.height - BLIP_VIEW_ICONS_Y_OFFSET, 13, 13);
	replyIconRect  =replyRect;
	quoteIconRect = quoteRect;
	
	if (replyView==nil){
		if ([[self blipMsg] canDeleteMessage] == NO){
			replyView = [[ClickableNSImageView alloc] initWithFrame:replyIconRect];
			[replyView setImage:[MessageView replyButton]];
		} else {
			replyView = [[ClickableNSImageView alloc] initWithFrame:replyIconRect];
			[replyView setImage:[MessageView deleteButton]];
		}
	}
	
	
	if (quoteView)
		return;
	quoteView = [[ClickableNSImageView alloc] initWithFrame:quoteIconRect];
	[quoteView setImage:[MessageView quoteButton]];
	[self addSubview:replyView];
	[self addSubview:quoteView];

}

#pragma mark mouse Events
-(void)viewDidMoveToWindow
{
	
	int options = NSTrackingMouseEnteredAndExited|NSTrackingActiveAlways;//|NSTrackingInVisibleRect;
	NSTrackingArea *ta;
	NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:ABL_SUBJECT_REPLY, ABL_SUBJECT, nil];
	ta = [[NSTrackingArea alloc] initWithRect:replyIconRect options:options owner:self userInfo:dict];
	[self addTrackingArea:ta];
	[dict release];
	dict = nil;
	[ta release];
	ta = nil;
	dict = [[NSDictionary alloc] initWithObjectsAndKeys:ABL_SUBJECT_PICTURE, ABL_SUBJECT, nil];
	ta = [[NSTrackingArea alloc] initWithRect:pictureIconRect options:options owner:self userInfo:dict];
	[self addTrackingArea:ta];
	[dict release];
	dict = nil;
	[ta release];
	ta = nil;
	dict = [[NSDictionary alloc] initWithObjectsAndKeys:ABL_SUBJECT_QUOTE, ABL_SUBJECT, nil];
	ta = [[NSTrackingArea alloc] initWithRect:quoteIconRect options:options owner:self userInfo:dict];
	[self addTrackingArea:ta];
	[dict release];
	dict = nil;
	[ta release];
	ta = nil;
	
}
-(void)mouseEntered:(NSEvent*)theEvent
{
	NSDictionary *dict = ([theEvent userData]);
	NSString *key = [dict objectForKey:ABL_SUBJECT];
	if (key == nil)
		return;
	if ([key isEqualToString:ABL_SUBJECT_REPLY]){

		if ([[self blipMsg] canDeleteMessage] ==NO){
			[replyView setImage:[MessageView replyButtonRollover]];
		}else {
			[replyView setImage:[MessageView deleteButtonRollover]];
		}

	}else if ([key isEqualToString:ABL_SUBJECT_QUOTE]){
		[quoteView setImage:[MessageView quoteButtonRollover]];
	
	}
	//[self setNeedsDisplay:YES];
}
-(void)mouseExited:(NSEvent*)theEvent
{

	if ([[self blipMsg] canDeleteMessage] ==NO)
		[replyView setImage:[MessageView replyButton]];
	else {
		[replyView setImage:[MessageView deleteButton]];
	}
	[quoteView setImage:[MessageView quoteButton]];

}
-(void)mouseUp:(NSEvent*)event 
{
	NSPoint p = [event locationInWindow];
	p = [self convertPoint:p fromView:nil];

	if (NSPointInRect(p, pictureIconRect) == YES){

		if (![blipMsg pictureData] && isYoutube2QtAvaible==NO)
			return;

		
		NSDictionary *d;
		if (isYoutube2QtAvaible){
			d = [NSDictionary dictionaryWithObject:[blipMsg youtubeQtLink] forKey:@"path"];
			NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
			[nc postNotificationName:ABL_YoutubePictureClickedNotification
							  object:self
							userInfo:d];
		}
		else{
			d = [NSDictionary dictionaryWithObjectsAndKeys:/*[blipMsg pictureData] ,@"picture",*/ [[AppController picturesDownloadDir] stringByAppendingPathComponent:[[blipMsg picturePath] lastPathComponent]], @"path",nil];
		
			NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
			[nc postNotificationName:ABL_PictureClickedNotification
							  object:self
							userInfo:d];
		}
	}else if (NSPointInRect(p, replyIconRect) == YES ){

		NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
		if ([blipMsg canDeleteMessage]==NO){
			NSString* receiver;
			if ([[blipMsg msgType] isEqualToString:@"PrivateMessage"]==YES){
				receiver = [NSString stringWithFormat:@">>%@", [blipMsg userName]];
			}
			else {
				receiver = [NSString stringWithFormat:@">%@", [blipMsg userName]];
			}
			NSDictionary *d = [NSDictionary dictionaryWithObject:receiver
														  forKey:ABL_USER_INFO_QUOTE];
			[nc postNotificationName:ABL_ReplyClickedNotification
							  object:self
							userInfo:d];
		}else{
			
			NSString* relativePath;
			if ([[blipMsg msgType] isEqualToString:ABL_PRIVATE_MESSAGE]==YES){
				relativePath = [NSString stringWithFormat:ABL_DELETE_PATH, @"private_messages" ,[blipMsg msgId]];
			}
			else if ([[blipMsg msgType] isEqualToString:ABL_DIRECTED_MESSAGE]==YES){
				relativePath = [NSString stringWithFormat:ABL_DELETE_PATH, @"directed_messages" ,[blipMsg msgId]];
			}
			else if ([[blipMsg msgType] isEqualToString:ABL_STATUS_MESSAGE]==YES){
				relativePath = [NSString stringWithFormat:ABL_DELETE_PATH, @"statuses" ,[blipMsg msgId]];
			}
			else{
				relativePath = [NSString stringWithFormat:ABL_DELETE_PATH, @"updates" ,[blipMsg msgId]];
			}
			NSDictionary *d = [NSDictionary dictionaryWithObject:relativePath
														  forKey:ABL_USER_INFO_DELETE];
			[nc postNotificationName:ABL_DeleteMessageClickedNotification
							  object:self
							userInfo:d];
		}	
		
	}else if (NSPointInRect(p, avatarRect) == YES){
		
		
		if ([blipMsg canDeleteMessage]==NO){
			NSString* receiver;
			NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
			if ([[blipMsg msgType] isEqualToString:@"PrivateMessage"]==YES){
				receiver = [NSString stringWithFormat:@">>%@", [blipMsg userName]];
			}
			else {
				receiver = [NSString stringWithFormat:@">%@", [blipMsg userName]];
			}
			NSDictionary *d = [NSDictionary dictionaryWithObject:receiver
														  forKey:ABL_USER_INFO_QUOTE];
			[nc postNotificationName:ABL_ReplyClickedNotification
							  object:self
							userInfo:d];
		}
	}else if (NSPointInRect(p, quoteIconRect) == YES){
		NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
		NSString* httpAddress;
		if ([[blipMsg msgType] isEqualToString:ABL_PRIVATE_MESSAGE]==YES){
			httpAddress = [NSString stringWithFormat:ABL_QUOTE_HTTP, @"pm" ,[blipMsg msgId]];
		}
		else if ([[blipMsg msgType] isEqualToString:ABL_DIRECTED_MESSAGE]==YES){
			httpAddress = [NSString stringWithFormat:ABL_QUOTE_HTTP, @"dm" ,[blipMsg msgId]];
		}
		else{
			httpAddress = [NSString stringWithFormat:ABL_QUOTE_HTTP, @"s" ,[blipMsg msgId]];
		}
		NSDictionary *d = [NSDictionary dictionaryWithObject:httpAddress
													  forKey:ABL_USER_INFO_QUOTE];
		[nc postNotificationName:ABL_QuoteClickedNotification
						  object:self
						userInfo:d];
	}else if (NSPointInRect(p, deleteIconRect) == YES ){

		NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
		NSString* relativePath;
		if ([[blipMsg msgType] isEqualToString:ABL_PRIVATE_MESSAGE]==YES){
			relativePath = [NSString stringWithFormat:ABL_DELETE_PATH, @"private_messages" ,[blipMsg msgId]];
		}
		else if ([[blipMsg msgType] isEqualToString:ABL_DIRECTED_MESSAGE]==YES){
			relativePath = [NSString stringWithFormat:ABL_DELETE_PATH, @"directed_messages" ,[blipMsg msgId]];
		}
		else if ([[blipMsg msgType] isEqualToString:ABL_STATUS_MESSAGE]==YES){
			relativePath = [NSString stringWithFormat:ABL_DELETE_PATH, @"statuses" ,[blipMsg msgId]];
		}
		else{
			relativePath = [NSString stringWithFormat:ABL_DELETE_PATH, @"updates" ,[blipMsg msgId]];
		}
		NSDictionary *d = [NSDictionary dictionaryWithObject:relativePath
													  forKey:ABL_USER_INFO_DELETE];
		[nc postNotificationName:ABL_DeleteMessageClickedNotification
						  object:self
						userInfo:d];
	}else if (NSPointInRect(p, userDescRect) == YES ){
		if ([blipMsg recipientName]!=nil && [[blipMsg recipientName] isEqualToString:[[AppController shared] userLogin]] == NO){
			[[AppController shared] openUserDashboard:[blipMsg recipientName]];
		} else {
			[[AppController shared] openUserDashboard:[blipMsg userName]];
		}
	}
}

#pragma mark pictures
+(NSImage*)quoteButton
{
	
	static NSImage* image = nil;
	if (image==nil){
		image = [NSImage imageNamed:@"quoteButton"];
	}
	return image;
}
+(NSImage*)quoteButtonRollover
{
	static NSImage* image = nil;
	if (image==nil){
		image = [NSImage imageNamed:@"quoteButton-rollover"];
	}
	return image;
}
+(NSImage*)replyButton
{
	static NSImage* image = nil;
	if (image==nil){
		NSBundle *bundle = [NSBundle mainBundle];
		NSString* imageName = [bundle pathForResource:@"replyButton" ofType:@"png"];
		image = [[NSImage alloc] initWithContentsOfFile:imageName];	
		//image = [NSImage imageNamed:@"replyButton"];

	}
	return image;
}
+(NSImage*)replyButtonRollover
{
	static NSImage* image = nil;
	if (image==nil){
		image = [NSImage imageNamed:@"replyButton-rollover"];
	}
	return image;
}
+(NSImage*)deleteButton
{
	static NSImage* image = nil;
	if (image==nil){
		image = [NSImage imageNamed:@"removeButton"];
	}
	return image;
}
+(NSImage*)deleteButtonRollover
{
	static NSImage* image = nil;
	if (image==nil){
		image = [NSImage imageNamed:@"removeButton-rollover"];
	}
	return image;
}
+(NSImage*)pictureButton
{
	static NSImage* image = nil;
	if (image==nil){
		image = [NSImage imageNamed:@"replyButton"];
	}
	return image;
}
+(NSImage*)avatarMask
{
	static NSImage* image = nil;
	if (image==nil){
		image = [NSImage imageNamed:@"avatar-mask.png"];
	}
	return image;
}
+(NSMutableDictionary*)blipTextAttributes
{
	static NSMutableDictionary *dict = nil;
	if (dict ==nil){
		dict = [[NSMutableDictionary alloc] init];
		NSShadow *shadow = [[NSShadow alloc] init];
		[shadow setShadowColor: [NSColor colorWithCalibratedRed:0 green:0 blue:0 alpha:0.5]];
		[shadow setShadowBlurRadius:1];
		[shadow setShadowOffset: NSMakeSize(0,-1)];
		[shadow autorelease];
		[dict setObject:shadow forKey:NSShadowAttributeName];
		[dict setObject:[NSFont fontWithName:@"Helvetica" size:12] forKey:NSFontAttributeName];
		[dict setObject:[NSColor whiteColor] forKey:NSForegroundColorAttributeName];
		//	
		[dict autorelease];
	}
	return dict;	
}
+(NSMutableDictionary*)blipDescriptionTextAttributes
{
	static NSMutableDictionary *dict = nil;
	if (dict ==nil){
		dict = [[NSMutableDictionary alloc] init];
		NSShadow *shadow = [[NSShadow alloc] init];
		[shadow setShadowColor: [NSColor colorWithCalibratedRed:0 green:0 blue:0 alpha:0.5]];
		//[shadow setShadowColor: [NSColor blackColor]];
		[shadow setShadowBlurRadius:1];
		[shadow setShadowOffset: NSMakeSize(0, -1)];
		[shadow autorelease];
		[dict setObject:shadow forKey:NSShadowAttributeName];
		[dict setObject:[NSFont fontWithName:@"Helvetica-Bold" size:11] forKey:NSFontAttributeName];
		[dict setObject:[NSColor colorWithCalibratedRed:descriptionFontColor green:descriptionFontColor blue:descriptionFontColor alpha:1] forKey:NSForegroundColorAttributeName];
		//	
		[dict autorelease];
	}
	return dict;	
}
+(NSShadow *)avatarShadow
{
	static NSShadow *shadow = nil;
	if (shadow ==nil){
		NSShadow *shadow = [[NSShadow alloc] init];
		[shadow setShadowColor: [NSColor blackColor]];// [NSColor colorWithCalibratedRed:shadowColor green:shadowColor blue:shadowColor alpha:1]];
		[shadow setShadowBlurRadius:5];
		[shadow setShadowOffset: NSMakeSize(2, -2)];
		[shadow autorelease];
		
	}
	return shadow;
}
/*
 - (NSImage *)createImageFromView:(NSView *)view {
 NSBitmapImageRep *imageRep = [view bitmapImageRepForCachingDisplayInRect:[view bounds]];
 unsigned char *bitmapData = [imageRep bitmapData];
 if (bitmapData != NULL) bzero(bitmapData, [imageRep bytesPerRow] * [imageRep pixelsHigh]);
 [view cacheDisplayInRect:[view bounds] toBitmapImageRep:imageRep];
 NSImage *image = [[NSImage alloc] init];
 [image addRepresentation: imageRep];
 
 return image;
 }
 */

@end
